def funct(n):
    for i2 in range(2, n):
        if n % i2 == 0:
            return False
    return True
numb = ['zero','one','two','three','four','five','six','seven','eight','nine']
u = input()
u_s = u.split()
s = ''
right = []
left = []
for i in u_s:
    s += str(numb.index(i))
s = int(s)
for i3 in range(2, s):
    if funct(i3):
        left.append(i3)
for i4 in range(s, 15000):
    if funct(i4):
        right.append(i4)
if s - min(right) <= max(left) - s:
    print(max(left))
else:
    print(min(right))